home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / javaScriptMode.tcl < prev    next >
Encoding:
Text File  |  2000-06-25  |  3.0 KB  |  92 lines

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  JavaScript mode - tools for editing JavaScript documents
  4.  # 
  5.  #  FILE: "javaScriptMode.tcl"
  6.  #                                    created: 97-02-09 13.00.54 
  7.  #                                last update: 00-06-25 16.18.06 
  8.  #  Author: Johan Linde
  9.  #  E-mail: <jlinde@telia.com>
  10.  #     www: <http://www.theophys.kth.se/~jl/Alpha.html>
  11.  #  
  12.  # Version: 1.1.2
  13.  # 
  14.  # Copyright 1997-2000 by Johan Linde
  15.  #  
  16.  # This software may be used freely, and distributed freely, as long as the 
  17.  # receiver is not obligated in any way by receiving it.
  18.  #  
  19.  # If you make improvements to this file, please share them!
  20.  # 
  21.  # ###################################################################
  22.  ##
  23.  
  24. alpha::mode JScr 1.1.2 JScrDummy {*.js *.JS} {
  25.     electricBraces electricColon electricSemicolon electricTab electricReturn} {
  26. } uninstall this-file maintainer {
  27.     "Johan Linde" jlinde@telia.com <http://www.theophys.kth.se/~jl/Alpha.html>
  28. } help {file "HTML Help"}
  29.  
  30. catch {unset JScrmodeVars(elecRBrace)}
  31. catch {unset JScrmodeVars(elecLBrace)}
  32. catch {unset JScrmodeVars(electricSemi)}
  33. catch {unset JScrmodeVars(electricTab)}
  34. catch {unset JScrmodeVars(electricColon)}
  35.  
  36. newPref v prefixString {//}  JScr
  37. newPref f wordWrap 0 JScr
  38. newPref v funcExpr {^[ \t]*function *([+-a-zA-Z0-9]+)} JScr
  39. newPref v parseExpr {^[ \t]*function *([+-a-zA-Z0-9]+)} JScr
  40. newPref v wordBreak {\w+} JScr
  41. newPref v wordBreakPreface {\W} JScr
  42. newPref v stringColor    green JScr
  43. newPref v commentColor red JScr
  44. newPref v keywordColor blue JScr
  45.  
  46.  
  47. regModeKeywords  -e {//} -b {/*} {*/} -c $JScrmodeVars(commentColor) -k $JScrmodeVars(keywordColor)  -s $JScrmodeVars(stringColor) JScr {
  48.     break case continue default delete do export for import in function if else new return switch this typeof var void while with true false }
  49.  
  50.  
  51. proc JScrDummy {} {}
  52.  
  53. proc JScr::carriageReturn {} {
  54.     global indentOnReturn electricColon
  55.     if {$electricColon && [lookAt [pos::math [getPos] - 1]] == ":"} {
  56.         if { [lookAt [getPos]] == "\r" } {
  57.             catch {bind::IndentLine}
  58.             endOfLine
  59.             insertText "\r"
  60.         } else {
  61.             set pos [getPos]
  62.             endOfLine
  63.             set t [getText $pos [getPos]]
  64.             replaceText $pos [getPos] ""
  65.             catch {bind::IndentLine}
  66.             endOfLine
  67.             insertText "\r"
  68.             insertText $t
  69.         }
  70.     } else {
  71.         insertText "\r"
  72.     }
  73.     if {$indentOnReturn} {catch {bind::IndentLine}}
  74. }
  75.  
  76. proc JScr::DblClick {from to} {
  77.     global HOME
  78.     select $from $to
  79.     set word [getText $from $to]
  80.     if {[grep "^${word}( |$)" [lindex [glob [file join $HOME JSreference index*]] 0]] != ""} {
  81.         editMark [lindex [glob [file join $HOME JSreference JS*]] 0] $word -r
  82.     } elseif {[lsearch -exact {break continue for function if else new return this var while with} $word] >= 0} {
  83.         if {$word == "if" || $word == "else"} {set word "if...else"}
  84.         editMark [lindex [glob [file join $HOME JSreference statements]] 0] $word -r
  85.     }
  86. }
  87.  
  88. set JScr::commentCharacters(General) [list "*" "//"]
  89. set JScr::commentCharacters(Paragraph) [list "/* " " */" " * "]
  90. set JScr::commentCharacters(Box) [list "/*" 2 "*/" 2 "*" 3]
  91.  
  92.